﻿'Joe Bittner
'Roman
'Rob Gasiewski 4/5/12
'March 23, 2012

' webservice method should have an input parameter for selected date, Calendar1.SelectedDate would be passed in 
' and the sql statement would incorporate the date into the where clause

Imports DBUtilitiesLibrary
Imports DARSClassLibrary

Public Class StudentAppointmentRegistration
    Inherits System.Web.UI.Page
    Dim ws As DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice

    'Page load: Loads the drop down list with Advisors
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Check if user is logged in
        If Session("CurrentUser") Is Nothing Then
            Response.Redirect("NotLoggedIn.aspx")
            Exit Sub
        End If

        If Not IsPostBack Then
            ws = New DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice
            Session("Pxy") = ws
            Dim ds As DataSet = ws.getAdvisors()
            ddlAdvisors.DataValueField = ds.Tables(0).Columns(0).ColumnName
            ddlAdvisors.DataSource = ds
            ddlAdvisors.DataBind()
            Dim li1 As New ListItem(" ", " ")
            ddlAdvisors.Items.Insert(0, li1)
            btnRegister.Visible = False

        End If
    End Sub


    'Register for an appointment
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRegister.Click
        Dim count As New Integer
        Dim cbox As CheckBox
        Dim ddList As DropDownList
        Dim I As Integer


        Dim Advisor As Integer = CInt(ddlAdvisors.SelectedValue)
        Dim objStudent As Student
        objStudent = CType(Session("CurrentUser"), Student)

        Dim Student As Integer = CInt(objStudent.studentID)
        Dim Reason As String
        Dim Dates As DateTime

        For I = 0 To (gvAppointments.Rows.Count - 1)
            ws = CType(Session("Pxy"), DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice)
            cbox = CType(gvAppointments.Rows(I).FindControl("cboxSelect"), CheckBox)

            If cbox.Checked Then


                ddList = CType(gvAppointments.Rows(I).FindControl("ddlReason"), DropDownList)
                Reason = ddList.SelectedValue
                Dates = CType(gvAppointments.Rows(I).Cells(1).Text, DateTime)

                ws.updateStudentAppointment(Advisor, Dates, Reason, Student)

            End If
        Next
        populateGridview()

    End Sub
    Public Sub populateGridview()
        Dim ds As DataSet = ws.getAvailableAppointments(ddlAdvisors.SelectedValue)
        Dim objdv As New DataView(ds.Tables(0))
        gvAppointments.DataSource = objdv
        gvAppointments.DataBind()



    End Sub



    Protected Sub ddlAdvisors_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAdvisors.SelectedIndexChanged
        ws = CType(Session("Pxy"), DO_NOT_MOVE_ME_FROM_THIS_PROJECT.DARSWebservice)
        Dim ds As DataSet = ws.getAvailableAppointments(ddlAdvisors.SelectedValue)
        Dim objdv As New DataView(ds.Tables(0))
        gvAppointments.DataSource = objdv
        gvAppointments.DataBind()
        btnRegister.Visible = True

    End Sub


    Protected Sub logout(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.ServerClick
        Session.Abandon()
        Response.Redirect("NotLoggedIn.aspx")
    End Sub

    Protected Sub home(ByVal sender As Object, ByVal e As EventArgs) Handles btnhome.ServerClick
        Response.Redirect("LandingPage.aspx")
    End Sub

  
End Class